﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pigmalion.Presenter.ClientePresenter;
using Pigmalion.BusinessEntities;

namespace Pigmalion.UIWF
{
    public partial class ClienteView : Form,IClienteView,IReceiver
    {
        ClientePresenter presenter; 

        public ClienteView()
        {
            InitializeComponent();

            presenter = new ClientePresenter(this);
        }

        public List<Cliente> GetDataClientes
        {
            get { return clienteBindingSource.Current as List<Cliente>;}
            set { clienteBindingSource.DataSource = value; }
        }

        private void ClienteView_Load(object sender, EventArgs e)
        {
            presenter.CargarClientes();
        }

        public void RefreshData()
        {
            throw new NotImplementedException();
        }

        public void New()
        {
            throw new NotImplementedException();
        }

        public void Edit()
        {
            throw new NotImplementedException();
        }

        public void Delete()
        {
            throw new NotImplementedException();
        }

        public void Buscar(object sender,EventArgs e)
        {
            presenter.BuscarCliente(txtCriterio.Text);
        }

        private void txtCriterio_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Buscar(sender, e);
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }


        public Cliente CurrentClient { get; set; }

        private void botonSeleccionar_Click(object sender, EventArgs e)
        {
            CurrentClient = clienteBindingSource.Current as Cliente;

            if (CurrentClient!=null)
            {
                Close();  
            }
            else
            {
                MessageBox.Show(this,"Debes Seleccionar un Registro","Mensaje",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
            }
            
        }

    }
}
